﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="recObjectionResponseform.aspx.cs"
    Inherits="SIPO.Web.Forms.Transaction.ObjectionResponseform" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="<%= ResolveUrl("~/styles/chosen/chosen.min.css") %>" rel="stylesheet"
        type="text/css" />
    <script src="<%= ResolveUrl("~/scripts/plupload/moxie.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/plupload/plupload.full.min.js") %>" type="text/javascript"></script>

    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/chosen/chosen.jquery.min.js") %>" type="text/javascript"></script>
    <style type="text/css">
        .style1
        {
            width: 242px;
        }
    </style>
</head>
<script type="text/javascript">

    $("#btnSave").button({ icons: { primary: "ui-icon-disk"} });
    $("#btnClose").button({ icons: { primary: "ui-icon-close"} });
    $('#btnClose').click(function () {
        parent.$('#dialog').dialog("close");

        return false;
    });
</script>
<script type="text/javascript">

    $(document).ready(function () {


        $("#txtNoSurat").upperCase();

        var uploader = new plupload.Uploader({
            runtimes: 'html5,flash,silverlight',
            browse_button: 'pickfiles',
            container: 'container',
            max_file_size: '5mb',
            url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>' + '?method=insertresponse',
            flash_swf_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.swf") %>',
            silverlight_xap_url: '<%= ResolveUrl("~/scripts/plupload/Moxie.xap") %>',
            filters: [
            { title: "Pdf files", extensions: "pdf" },
            { title: "Excel files", extensions: "xls,xlsx" },
			{ title: "Text files", extensions: "txt" },
			{ title: "Image files", extensions: "jpeg,jpg,gif,png" },
            { title: "Word files", extensions: "doc,docx" },
			{ title: "PowerPoint files", extensions: "ppt,pptx" }
		],
            resize: { width: 320, height: 240, quality: 90 }
        });

        uploader.bind('Init', function (up, params) {

            var msg = 'Untuk dapat melakukan proses unggah / upload dokumen, browser anda harus mendukung salah satu teknologi, HTML 5 / Flash / Silverlight';

            if (params.runtime == 'html5') {
                msg = '';
            } else if (params.runtime == 'flash') {
                msg = '';
            } else if (params.runtime == 'silverlight') {
                msg = ''
            }

            if (msg != '') {
                alert(msg);
            }

        });

        uploader.init();

        uploader.bind('FilesAdded', function (up, files) {

            if (up.files.length > 1) {
                alert('Hanya diperbolehkan satu file untuk di upload!');
                return false;
            }

            $.each(files, function (i, file) {
                $('#filelist').append(
                        '<div id="' + file.id + '">' +
                file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' + '</div>');
            });

            up.refresh(); // Reposition Flash/Silverlight
        });

        uploader.bind('FileUploaded', function (up, file, info) {

            var err = JSON.parse(info.response);
            alert(err.Message);

        });

        uploader.bind('Error', function (up, err) {
            $('#filelist').append("<div>Error: " + err.code +
			", Message: " + err.message + (err.file ? ", File: " + err.file.name : "") + "</div>");

            up.refresh(); // Reposition Flash/Silverlight

        });


        var rules = {
            txtNoSuratKeberatan: "required",
            txtNoSurat: "required",
            txtTglSurat: "required"
        };
        var messages = {
            txtNoSuratKeberatan: "No. Surat keberatan harus di pilih",
            txtNoSurat: "No Surat harus di isi",
            txtTglSurat: "Tanggal Surat harus di isi"
        };

        var validator = new jQueryValidatorWrapper("form1", rules, messages);

        $("#txtNoSurat").inputmask("Regex", { regex: "[0-9/ .-:A-Za-z()-]*" });

        $("#txtCatatan").inputmask("Regex", { regex: "[A-Za-z-,.0-9 ]*" });

        var date = new Date();
        var currentMonth = date.getMonth();
        var currentDate = date.getDate();
        var currentYear = date.getFullYear();

        $("#txtTglSurat").datepicker({ showWeek: true, showButtonPanel: true,
            changeMonth: true,
            changeYear: true,
            dateFormat: 'dd/mm/yy',
            minDate: 0
        });

        $('#txtTglSurat').inputmask("d/m/y", { "placeholder": "dd/mm/yyyy" });

        $("#btnSave").click(function (e) {

            e.preventDefault();

            if (!validator.validate())
                return;

            var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>';
            var add = '<%= Request.Params["isedit"] %>';

            if (add == 0) {

                if (uploader.files.length > 0) // Insert with uploaded file.
                {
                    uploader.settings.multipart_params = {
                        'txtNoSurat': encodeURIComponent($('#txtNoSurat').val()),
                        'txtTglSurat': encodeURIComponent($('#txtTglSurat').val()),
                        'txtCatatan': encodeURIComponent($('#txtCatatan').val()),
                        'hfID': encodeURIComponent($('#hfID').val()),
                        'hfObjectionId' : encodeURIComponent($('#hfObjectionId').val()),
                        'hfObjectionNo': encodeURIComponent($('#hfObjectionNo').val())
                    };

                    uploader.settings.url = handlerUrl + '?method=insertresponse';
                    uploader.start();
                }
                else {

                    $.post('<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>' + '?method=insertresponse',
                                $("#form1").serializeNoViewState())
                            .done(function (data) {
                                var r = JSON.parse(data);
                                alert(r.Message);
                            })
                            .fail(function () {
                                alert('Data gagal di tambah!');
                            });
                }
            }
            else {

                if (uploader.files.length > 0) // Update with uploaded file.
                {
                    uploader.settings.multipart_params = {
                        'txtNoSurat': encodeURIComponent($('#txtNoSurat').val()),
                        'txtTglSurat': encodeURIComponent($('#txtTglSurat').val()),
                        'txtCatatan': encodeURIComponent($('#txtCatatan').val()),
                        'hfID': encodeURIComponent($('#hfID').val()),
                        'hfObjectionId': encodeURIComponent($('#hfObjectionId').val())
                    };

                    uploader.settings.url = handlerUrl + '?method=insertresponse';
                    uploader.start();

                }
                else {

                    $.post('<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>' + '?method=insertresponse',
                                $("#form1").serializeNoViewState())
                            .done(function (data) {
                                var r = JSON.parse(data);
                                alert(r.Message);
                            })
                            .fail(function () {
                                alert('Data gagal di ubah!');
                            });

                }

            }

            parent.$('#dialog').dialog('close');

            setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);

            return false;

        });

    });
</script>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="0">
            <tr>
                <td class="style1">
                    No. Surat Keberatan
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txtNoSuratKeberatan" runat="server" Width="100" Enabled="false"></asp:TextBox>&nbsp;<span
                        style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    No. Surat
                    Tanggapan Sementara</td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txtNoSurat" runat="server" Width="100"></asp:TextBox>&nbsp;<span
                        style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    Tgl. Surat
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txtTglSurat" runat="server" Width="100" MaxLength="10"></asp:TextBox>&nbsp;<span
                        style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    Catatan
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txtCatatan" TextMode="MultiLine" runat="server" Width="300"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    Lampiran
                </td>
                <td>
                    :
                </td>
                <td>
                    <div id="container">
                        <a id="pickfiles" class="plupload_button plupload_add ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                            href="#"><span class="ui-button-icon-primary ui-icon ui-icon-circle-plus" /><span
                                class="ui-button-text">Add Files</span> </a>
                        <br />
                        <div id="filelist">
                        </div>
                    </div>
                </td>
                &nbsp;
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
                <td>
                    <asp:HiddenField ID="hfID" runat="server" />
                    <asp:HiddenField ID="hfNoSurat" runat="server" />
                    <asp:HiddenField ID="hfObjectionId" runat="server" />
                    <asp:HiddenField ID="hfObjectionNo" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;
                </td>
                <td>
                    <div style="text-align: right; padding-top: 10px;">
                        <button id="btnSave" type="button">
                            Simpan</button>
                        <button id="btnClose" type="button">
                            Batal</button>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
